package com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.viewModel

import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.async
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.*
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.remote.BaseData
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.repo.MarkRepo
import androidx.databinding.ObservableArrayList
import androidx.databinding.ObservableField
import androidx.lifecycle.ViewModel
import io.reactivex.Single

/**
 * Created by Dadong on 2020/9/22
 * Describe:
 */
class MarkViewModel constructor(private var repo: MarkRepo) : ViewModel() {
    val title: ObservableField<String> = ObservableField<String>("")


    /*
    * 获取试卷预览(答题卡+试题详情)
    * */
    private val paperPreviewInfor: ObservableField<PaperPreviewInfor> = ObservableField<PaperPreviewInfor>()
    fun getPaperPreviewInfor(paperId: String,setId: String) =
            repo.getPaperPreviewInfor(paperId,setId)
                    .async()
                    .doOnSuccess {
                        paperPreviewInfor.set(it.data)
                    }

    /*
    * 获取试卷讲评(答题卡+整体详情)
    * */
    fun getPaperEvaluationInfor(paperId: String,setId:String) =
            repo.getPaperEvaluationInfor(paperId,setId)
                    .async()
                    .doOnSuccess {
                    }

    /*
     *获取讲评单个试题(详情)
     * */
    val quesEvaluationDeatil: ObservableField<QuesEvaluationDetail> = ObservableField<QuesEvaluationDetail>()
    fun getQuesEvaluationDeatil(paperId: String, quesId: String, startIndex: Int) =
            repo.getQuesEvaluationDeatil(paperId, quesId, startIndex)
                    .async()
                    .doOnSuccess {
                        quesEvaluationDeatil.set(it.data)
                    }

    /*
    * 获取某个学生试卷分析(答题卡+详情)
    * */
    fun getPaperAnalysisInfor(stuId: String, paperId: String,setId:String) =
            repo.getPaperAnalysisInfor(stuId, paperId,setId)
                    .async()
                    .doOnSuccess {
                    }

    /*
    * 获取当前学生认知等级
    * */
    fun getCognitiveGrade(stuId:String,paperId: String,zsdArea:String) =
            repo.getCognitiveGrade(stuId,paperId,zsdArea)
                    .async()
                    .doOnSuccess {
                    }

    /*
     *获取纠错类型
     * */
    val errorRecoveryEntity: ObservableArrayList<ErrorRecovery> = ObservableArrayList()
    fun getErrorConfig() =
            repo.getErrorConfig()
                    .async()
                    .doOnSuccess {
                        errorRecoveryEntity.addAll(it.data)
                    }


    /*
    * 提交纠错信息
    * */
    private var ErrorCorrectionResult: String = ""
    fun addQuesErrorCorrection(
            quesId: String,
            errorType: String,
            errorDescribe: String
    ): Single<BaseData<String>> =
            repo.addQuesErrorCorrection(quesId, errorType, errorDescribe)
                    .async()
                    .doOnSuccess {
                        ErrorCorrectionResult = it.data
                    }


    /*
      * 导出讲评信息
      * */
    fun exportComment(paperId: String,setId: String, isAnswerAnalysis: Boolean, isZsd: Boolean, isListenVideo: Boolean, isListenText: Boolean) =
            repo.exportComment(paperId,setId, isAnswerAnalysis, isZsd, isListenVideo, isListenText)
                    .async()
                    .doOnSuccess {
                    }


    /*
      * 组卷主页面获取试卷名称与PaperID
      * */
    private var templetPaperInit: ObservableField<TempletPaperInit> = ObservableField<TempletPaperInit>()
    fun getPaperInit(
            stuId: String,
            layer: Int
    ) =
            repo.getPaperInit(stuId, layer)
                    .async()
                    .doOnSuccess {
                        templetPaperInit.set(it.data)
                    }

    /*
    * 获取试卷生词率等级配置信息
    * */
    private var templetExceedList: ObservableField<TempletExceedList> = ObservableField<TempletExceedList>()
    fun getExceedList() =
            repo.getExceedList()
                    .async()
                    .doOnSuccess {
                        templetExceedList.set(it.data)
                    }

    /*
     * 获取语法专项的专题列表
     * */
    private var templetGrammarSpecificListInfor: ObservableField<TempletGrammarSpecificListInfor> = ObservableField<TempletGrammarSpecificListInfor>()
    fun getTopicList(
            stuId: String
    ): Single<BaseData<TempletGrammarSpecificListInfor>> =
            repo.getTopicList(stuId)
                    .async()
                    .doOnSuccess {
                        templetGrammarSpecificListInfor.set(it.data)
                    }

    /*
 * 获取专题的知识点信息（支持多个专题同时查询）
 * */
    fun getTopicKlg(
            stuId: String,
            topicIds: String
    ): Single<BaseData<TopicGrammarKlgInfor>> =
            repo.getTopicKlg(stuId, topicIds)
                    .async()
                    .doOnSuccess {
                    }

    /*
    * 获取模板列表信息，用于模板管理
    * */
    private var templetGrammarPaperListInfor: ObservableField<TempletPaperListInfor> = ObservableField<TempletPaperListInfor>()
    fun getTempletBriefList(
            templetType: Int
    ): Single<BaseData<TempletPaperListInfor>> =
            repo.getTempletBriefList(templetType)
                    .async()
                    .doOnSuccess {
                        templetGrammarPaperListInfor.set(it.data)
                    }

    /*
     * 获取模板管理的选中模板的题型信息
     * */
    private var templateTypeListInfor: ObservableField<TemplateTypeListInfor> = ObservableField<TemplateTypeListInfor>()
    fun getTempletTypeList(
            templetId: String
    ) =
            repo.getTempletTypeList(templetId)
                    .async()
                    .doOnSuccess {
                        templateTypeListInfor.set(it.data)
                    }

    /*
     * 获取自定义模板适用题型
     * */
    private var templetSelectedTypeListInfor: ObservableField<TempletSelectedTypeListInfor> = ObservableField<TempletSelectedTypeListInfor>()
    fun getSelectedTypeList(
            templetType: Int
    ): Single<BaseData<TempletSelectedTypeListInfor>> =
            repo.getSelectedTypeList(templetType)
                    .async()
                    .doOnSuccess {
                        templetSelectedTypeListInfor.set(it.data)
                    }

    /*
  * 保存自定义模板
  * */
    fun saveCustomizeTemplet(
            strCustomtemplet: String
    ): Single<BaseData<String>> =
            repo.saveCustomizeTemplet(strCustomtemplet)
                    .async()
                    .doOnSuccess {

                    }

    /*
     *删除自定义模板
      */
    private var deleResult = ""
    fun delCustomizeTemplet(
            templetId: String
    ) =
            repo.delCustomizeTemplet(templetId)
                    .async()
                    .doOnSuccess {
                        deleResult = it.data
                    }

    /*
    * 发起组卷
    * */
    fun startSelected(
            paperId: String,
            stuId: String,
            level: Int,
            layer: Int,
            templetId: String,
            langId: String,
            topicIds: String,
            paperName: String
    ) = repo.startSelected(paperId, stuId, level, layer, templetId, langId, topicIds, paperName)
            .async()
            .doOnSuccess {
            }

    /*
* 获取组卷抽题进度
* */
    fun getSelectedProgress(
            paperId: String,
            stuId: String,
            layer: Int,
            templetId: String
    ) = repo.getSelectedProgress(paperId, stuId, layer, templetId)
            .async()
            .doOnSuccess {
            }

    /*
     * 生成试卷（抽题结束后，调用接口，生成试卷结构信息）
     * */
    fun generatePaper(
            paperId: String,
            paperName: String,
            stuId: String,
            layer: Int,
            templetId: String
    ) = repo.generatePaper(paperId, paperName, stuId, layer, templetId)
            .async()
            .doOnSuccess {
            }

    /*
  * 发布试卷
  * */
    fun publishPaper(
            paperId: String,
            stuId: String,
            layer: Int
    ) = repo.publishPaper(paperId, stuId, layer)
            .async()
            .doOnSuccess {
            }

    /*
    * 删除未发布试卷
    * */
    fun delPaper(
            paperId: String,
            stuId: String,
            layer: Int
    ) = repo.delPaper(paperId, stuId, layer)
            .async()
            .doOnSuccess {
            }

    /*
   * 获取语言能力专项列表信息
   * */
    fun getAllAbilityBaseInfo(
            stuId: String
    ) = repo.getAllAbilityBaseInfo(stuId)
            .async()
            .doOnSuccess {
            }

    /*
    * 获取语言能力知识点信息
    * */
    fun getLangKlgList(
            stuId: String,
            langId: String
    ) = repo.getLangKlgList(stuId, langId)
            .async()
            .doOnSuccess {
            }

    /*
    * 获取组卷生成待审核试卷内容(非口语)
    * */
    fun getReviewPaperInfo_1v1(
            paperId: String,
            stuId: String
    ) = repo.getReviewPaperInfo_1v1(paperId, stuId)
            .async()
            .doOnSuccess {
            }

    /*
    * (一对一）：试卷预览
    * */
    fun getPreviewPaperInfo_1v1(
            paperId: String,
            setId:String
    ) = repo.getPreviewPaperInfo_1v1(
            paperId,setId
    )
            .async()
            .doOnSuccess {
            }

    /*
    *某学生的作业情况预览
    * */
    fun getPaperAnalysisInfor_1v1(
            paperId: String
    ) = repo.getPaperAnalysisInfor_1v1(paperId)
            .async()
            .doOnSuccess {

            }


    /*
   * （一对一）获取普通替换试题
   * */
    fun getReplaceQuesInfo_1v1(
            stuId: String,
            typeNo: String,
            genreId: Int,
            specialFeature: String,
            itemNum: Int,
            mFilterID: String,
            sFilterID: String,
            importKlgList: ArrayList<String>,
            mainKlgList: ArrayList<String>,
            themeKlgList: ArrayList<String>,
            isTheme: Boolean,
            startIndex: Int
    ) = repo.getReplaceQuesInfo_1v1(
            stuId,
            typeNo,
            genreId,
            specialFeature,
            itemNum,
            mFilterID,
            sFilterID,
            importKlgList,
            mainKlgList,
            themeKlgList,
            isTheme,
            startIndex
    )
            .async()
            .doOnSuccess {
            }

    /*
 * 保存替换的试题
 * */
    fun saveReplacedQues(quesId: String,
                         originalQuesId: String,
                         paperId: String,
                         paperType: Int) =
            repo.saveReplacedQues(quesId, originalQuesId, paperId, paperType)
                    .async()
                    .doOnSuccess {
                    }

    /*
  * （一对一）获取主题知识点相关信息
  * */
    fun getTypeThemeList(typeNo: String,
                         genreId: Int) =
            repo.getTypeThemeList(typeNo, genreId)
                    .async()
                    .doOnSuccess {

                    }

    /*
   * 获取唯一码对应的数字化编码
   * */
    var uniqueCodeResult = ""
    fun getKlgCode(uniqueCode: String) =
            repo.getKlgCode(uniqueCode)
                    .async()
                    .doOnSuccess {
                        uniqueCodeResult = it.message
                    }

    /*
   * 导出学生成绩
   * */
    fun exportPaperScore(paperId: String,setId:String) =
            repo.exportPaperScore(paperId,setId)
                    .async()
                    .doOnSuccess {
                    }

    /*
    * 改变音频播放速度
    * */
    fun adjustAudioSpeed(
            audioSpeed: Double,
            paperId: String,
            quesId: String
    ) =
            repo.adjustAudioSpeed(audioSpeed, paperId, quesId)
                    .async()
                    .doOnSuccess {
                    }


    /*
    * 是否开启班级认知诊断
    * */
        fun getIsOpenClassRZZD_App() =
                repo.getIsOpenClassRZZD_App()
                        .async()
                        .doOnSuccess {
                        }

    /*
  * 是否切换到个人认知诊断
  * */
    fun getIsChangeStu_App() =
            repo.getIsChangeStu_App()
                    .async()
                    .doOnSuccess {
                    }


    /*
    * 获取班级知识点域
    * */
    fun getZsdArea_App() =
            repo.getZsdArea_App()
                    .async()
                    .doOnSuccess {
                    }

    /*
    * 班级预估成绩
    * */
    fun getClassTotalScore_App() =
            repo.getClassTotalScore_App()
                    .async()
                    .doOnSuccess {
                    }

    /*
   * 获取认知指数主页面详情
   * */
    fun getClassCognitiveIndex_App(zsdArea: String) =
            repo.getClassCognitiveIndex_App(zsdArea)
                    .async()
                    .doOnSuccess {
                    }

    /*
    * 班级学生成绩得分分布图弹窗
    * */
    fun getScoreDistre_App(flag: Int) =
            repo.getScoreDistre_App(flag)
                    .async()
                    .doOnSuccess {
                    }

    /*
      * 总评成绩学生进步/退步人数弹窗
      * */
    fun getStuNum_App() =
            repo.getStuNum_App()
                    .async()
                    .doOnSuccess {
                    }

    /*
    *班级认知指数区域分布表-弹窗
    * */
    fun getRangeClassTableInfo_App(flag: Int, zsdArea: String) =
            repo.getRangeClassTableInfo_App(flag, zsdArea)
                    .async()
                    .doOnSuccess {
                    }

    /*
   * 班级认知荣誉榜
   * */
    fun getCognitiveIndexHonorRank_App(zsdArea: String) =
            repo.getCognitiveIndexHonorRank_App(zsdArea)
                    .async()
                    .doOnSuccess {
                    }

    /*
      *词汇认知主页面
      * */
    fun getClassVocablary_App(zsdArea: String) =
            repo.getClassVocablary_App(zsdArea)
                    .async()
                    .doOnSuccess {
                    }

    /*
 * 词汇量区域分布表-弹窗
 * */
    fun getRangeClassVocabInfo_App(flag: Int, typeStr: String, zsdArea: String) =
            repo.getRangeClassVocabInfo_App(flag, typeStr, zsdArea)
                    .async()
                    .doOnSuccess {
                    }

    /*
    *语法认知主页面
    * */
    fun getClassGrammar_App(zsdArea: String) =
            repo.getClassGrammar_App(zsdArea)
                    .async()
                    .doOnSuccess {
                    }

    /*
  * 语法量区域分布表-弹窗
  * */
    fun getRangeClassGrammarInfo_App(flag: Int,zsdArea: String) =
            repo.getRangeClassGrammarInfo_App(flag, zsdArea)
                    .async()
                    .doOnSuccess {
                    }

    /*
    * 语言能力认知
    * */
    fun getLanguageForClass_App() =
            repo.getLanguageForClass_App()
                    .async()
                    .doOnSuccess {
                    }

    /*
    * 语言能力认知情况弹窗
    * */
    fun getAbilityForClass_App(abilityName: String) =
            repo.getAbilityForClass_App(abilityName)
                    .async()
                    .doOnSuccess {
                    }

    /*
     * 做题特点主界面
     * */
    fun getClassExerciseTrait_App() =
            repo.getClassExerciseTrait_App()
                    .async()
                    .doOnSuccess {
                    }

    /*
    * 学习特点主界面
    * */
    fun getStudyFeatureForClass_App() =
            repo.getStudyFeatureForClass_App()
                    .async()
                    .doOnSuccess {
                    }

    /*
  * 移动端班级学习建议
  * */
    fun getClassStudyAdvice_App(zsdArea: String) =
            repo.getClassStudyAdvice_App(zsdArea)
                    .async()
                    .doOnSuccess {
                    }

}